<template>
  <div>
    <common-head title="联系人列表"></common-head>
    <div class="con">
      <van-address-list v-model="chosenAddressId"
       default-tag-text="默认" :list="contacts"
        @add="onAdd" @edit="onEdit" @select="changeContact" />
    </div>
  </div>
</template>

<script>
import CommonHead from '@components/CommonHead'
import { mapState, mapMutations } from 'vuex'
export default {
  data(){
    return{
      chosenAddressId:'1'
    }
  },
  components: {
    CommonHead
  },
  computed: {
    ...mapState({
      contacts: (state) => state.address.contacts
    })
  },
  methods: {
    onAdd(){
      this.$router.push('/addContact')
    },
    onEdit(item, index) {
      this.$router.push(`/editContact/${index}`)
    },
    changeContact(contact, index){
      console.log(contact)
      // 切换联系人
      this.setNowOrderContact(contact)
      this.$router.go(-1)
    },
    ...mapMutations('order',['setNowOrderContact'])
  },
}
</script>

<style lang="scss" scoped>
</style>